<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
  
 </body>
</html>
<script>
	var str = 'www.ucai.cn.ucai';
	console.log(str.replace('ucai', 'sina'));
	//补充字符串方法replace的另外一种用法:要替换的内容第二个参数传一个函数
	console.log(str.replace('ucai', function(){
		//一系列的运算后得到想要的结果
		return 'sina';
	}));

	console.log(str.replace(/ucai/, 'sina'));
	console.log(str.replace(/ucai/, function(){
		return 'baidu';
	}));
	//g表示全局匹配
	//第二个参数如是函数，可以接收两个形参
	console.log(str.replace(/ucai/g, function(a, b){
		console.log(a);
		console.log(b);
		return 'baidu';
	}));
</script>
